<layout name="site" />
<h3 class="mt10 tc sy">{$category.name}</h3>
<section id="news" class="lists wrapper mt10 ms" >
  <tag:article id="vo" limit="10">
  <div class="lists-item">
    <a href="{$vo.url}">{$vo.name}</a>
  </div>
  </tag:article>
  <div class="auto tc mt10" id="read-more" style="text-align:center;padding:10px 0px 15px 0px;">
	<a class="btn btn-blue">更多>></a>
  </div>
</section>

<script type="text/javascript">
	(function() {
		var readMore = document.getElementById( "read-more" ),
			news = document.getElementById("news"),
			page = 2,
			cat = {$_GET['id']},
			sid = {$_GET['sid']};
		
		readMore.addEventListener( "click", getMoreNews, false );
		
		function getMoreNews() {
			ajax("__CONTROLLER__/more", {p: page++, cat: cat, sid: sid}, function(data){
				if ( data.error == 0 ) {
					addArticle( data.extra )
				} else {
					cosole.log("获取失败。")
				}
			}, "post")
		}
	
		function addArticle( data ) {
			if ( data.length ) {
				for(var i=0; at=data[i]; i++) {
					var article = document.createElement("article"),
						html = "",
						thumb = "";
					article.setAttribute("class", "clearfix bb");
					
					html = 	"<div class=\"lists-item\"><a href='" +at.url+ "'>"
					   + at.name
					   + "</a></div>";
					
					article.innerHTML = html;
					
					news.insertBefore( article, readMore );
				
				}
			} else {
				readMore.innerHTML = "没有更多了……";
			}
		}
		//ajax(路径，数据，成功函数，提交方式)
		function ajax(url, json, fnSucc, type)
		{
			var oAjax;
			//创建ajax对象
			oAjax = new XMLHttpRequest();
			//发送的数据
			var data = "";
			for(var i in json) {
				data += i + "=" + json[i] + "&";
			}
			data = data.replace(/&$/,"");
			//GET或者POST
			if(type == "get") {
				oAjax.open("GET", url+"?"+data+new Date().getTime(), true);
				oAjax.send();
			} else if(type == "post") {
				oAjax.open("POST", url, true);
				oAjax.setRequestHeader("Content-type","application/x-www-form-urlencoded");
				oAjax.send(data);
			}
			oAjax.onreadystatechange = function() {
				if(oAjax.readyState == 4) {
					if(oAjax.status == 200) {
						//返回的json字符串转换为对象
						fnSucc(eval("("+oAjax.responseText+")"));
					}
				}
				
			}
		};
	})()
</script>